package orthoplanner.com.google.code.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;

import orthoplanner.com.google.code.eventhandlers.DrawableColorChooserHandler;
import orthoplanner.com.google.code.eventhandlers.DrawableDeleteHandler;
import orthoplanner.com.google.code.eventhandlers.SlWidthHandler;
import orthoplanner.com.google.code.tools.Drawable;

public class AdvanceDrawablePanel extends JPanel {

	private static final long serialVersionUID = 2436091968710801340L;
	private Drawable drawable;
	private JLabel lIcon;
	private JColorChooser colorChooser;
	private JSlider slWidth;
	private JButton bColorChooser,bDelete;
	private JFrame colorChooserFrame;
	private JButton okColor;
	public AdvanceDrawablePanel(Drawable drawable,DrawableDeleteHandler ddh){
		super();
		this.drawable=drawable;
		okColor=new JButton("OK");
		colorChooserFrame=new JFrame();
		colorChooserFrame.setLayout(new FlowLayout());
		colorChooserFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		slWidth=new JSlider(JSlider.HORIZONTAL,1,25,drawable.getStrokeWeight());
		lIcon=new JLabel(drawable.getName());
		lIcon.setPreferredSize(new Dimension(100,20));
		lIcon.setFont( new Font("SansSerif", Font.BOLD, 12));
		bDelete=new JButton("X");
		bDelete.setPreferredSize(new Dimension(30,20));
		bDelete.setForeground(Color.red);
		bDelete.setFont( new Font("SansSerif", Font.BOLD, 12));
		colorChooser=new JColorChooser(drawable.getColor());
		colorChooserFrame.add(colorChooser);
		bColorChooser=new JButton(" ");
		bColorChooser.setPreferredSize(new Dimension(30,20));
		bColorChooser.setBackground(drawable.getColor());
		GridBagConstraints gbc=new GridBagConstraints();
		setLayout(new GridBagLayout());
		gbc.gridx=0;
		gbc.gridy=0;
		add(bDelete,gbc);
		gbc.gridx=1;
		add(lIcon,gbc);
		gbc.gridx=2;
		add(bColorChooser,gbc);
		gbc.gridx=3;
		add(slWidth,gbc);
		slWidth.setPreferredSize(new Dimension(150,20));
		bColorChooser.addMouseListener(new DrawableColorChooserHandler(colorChooserFrame));
		//colorChooserFrame.setPreferredSize(new Dimension(200,200));
		colorChooserFrame.add(okColor);
		okColor.setPreferredSize(new Dimension(40,20));
		okColor.addMouseListener(new OkColorListener(colorChooser,drawable,bColorChooser,colorChooserFrame));
		slWidth.addChangeListener(new SlWidthHandler(drawable));
		setBorder(BorderFactory.createLineBorder(Color.blue));
		bDelete.addMouseListener(ddh);
		
	}
	public Drawable getDrawable() {
		return drawable;
	}
	
	
}
